package com.org.oracle.mongodb.entity;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.IOException;

/**
 * @author suze
 * @date 2024/8/18
 * @time 20:44
 **/
@Document(collection = "members")
@Data
public class Member {//知识圈成员

    private String id;
    private String circleId;
    private User user;
    public class User {
        /**
         * 头像
         */
        private String avatar;
        private String name;
        private String userid;
    }
    //User的set get方法
    public User getAvatar() {
        return user;
    }
    public void setAvatar(String  avatar) {
        user.avatar = avatar;
    }
    public void setName(String name) {
        user.name = name;
    }
    public void setUserid(String userid){
        user.userid = userid;
    }

    @Override
    public String toString() {
        try {
            ObjectMapper mapper = new ObjectMapper();
            return mapper.writeValueAsString(this);
        } catch (IOException e) {
            // Handle exception
            e.printStackTrace();
            return "Error converting to JSON: " + e.getMessage();
        }
    }

}
